from typing import List


class Solution:
    def matrixReshape(self, nums: List[List[int]], r: int, c: int) -> List[List[int]]:
        count = 0
        l = []
        for row in nums:
            for num in row:
                l.append(num)
                count += 1

        res = []
        index = 0
        print(len(l))
        if count != r * c:
            return nums
        for i in range(r):
            tmp = []

            for j in range(c):
                print(i, j, index)
                if index < len(l):
                    tmp.append(l[index])
                    index += 1
                else:
                    break
            res.append(tmp)
            print(",", index)
            if index >= len(l):
                break
        return res
